package site.microkang.house.service;

import cn.hutool.system.UserInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import site.microkang.house.mapper.TalentIdentificationInfoMapper;
import site.microkang.house.model.dto.TalentIdentificationInfoDto;
import site.microkang.house.model.entity.TalentIdentificationInfoEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liukang
 * @date 2021/3/19 21:32
 */
@Service
@Transactional(readOnly = true)
public class TalentIdentificationInfoService {
    @Autowired(required = false)
    private TalentIdentificationInfoMapper talentIdentificationInfoMapper;

    /**
     * 条件查询数据
     * @param dto
     * @return
     */
    public List<TalentIdentificationInfoDto> selectList(TalentIdentificationInfoDto dto) {
        QueryWrapper<TalentIdentificationInfoEntity> queryWrapper = new QueryWrapper<>();
        List<TalentIdentificationInfoEntity> list = talentIdentificationInfoMapper.selectList(queryWrapper);
        List<TalentIdentificationInfoDto> dtos = new ArrayList<>();
        list.forEach(v -> {
            dtos.add(TalentIdentificationInfoDto.builder()
                    .baseUrl(v.getBaseUrl())
                    .content(v.getContent())
                    .releaseTime(v.getReleaseTime())
                    .title(v.getTitle())
                    .xlsLinkAddr(v.getXlsLinkAddr())
                    .build());
        });
        return dtos;
    }

    @Transactional(readOnly = false)
    public int insert(TalentIdentificationInfoEntity entity) {
        int insert = talentIdentificationInfoMapper.insert(entity);
        return insert;
    }
}
